package org.javaongems.client.rt.util;

public class ArrayUtils {
	final static public String COMMA_DELIM = ",";
	final static public String SEMICOLON_DELIM = ";";
	final static public String COLON_DELIM = "\\:";
	
	static public String constructStringList(String[] args, String delim) {
		StringBuffer buff = new StringBuffer();
		for (int i = 0; i < args.length; i++) {
			if (i > 0)
				buff.append(delim);
			buff.append(args[i]);
		}
		return buff.toString();
	}

	static public String constructStringList(int[] args, String delim) {
		StringBuffer buff = new StringBuffer();
		for (int i = 0; i < args.length; i++) {
			if (i > 0)
				buff.append(delim);
			buff.append(args[i]);
		}
		return buff.toString();
	}

	static public String constructStringList(double[] args, String delim) {
		StringBuffer buff = new StringBuffer();
		for (int i = 0; i < args.length; i++) {
			if (i > 0)
				buff.append(delim);
			buff.append(args[i]);
		}
		return buff.toString();
	}
	
	static public String constructStringList(boolean[] args, String delim) {
		StringBuffer buff = new StringBuffer();
		for (int i = 0; i < args.length; i++) {
			if (i > 0)
				buff.append(delim);
			buff.append(args[i]);
		}
		return buff.toString();
	}
	
	static public String[] parseStringArray(String val, String delim) {
		String[] ret = val.split(delim);
		return ret;
	}

	static public int[] parseIntArray(String val, String delim) {
		String[] retAsStr = parseStringArray(val, delim);
		int[] ret = new int[retAsStr.length];
		for (int i = 0; i < ret.length; i++) 
			ret[i] = Integer.parseInt(retAsStr[i]);
		return ret;
	}
	
	static public double[] parseDoubleArray(String val, String delim) {
		String[] retAsStr = parseStringArray(val, delim);
		double[] ret = new double[retAsStr.length];
		for (int i = 0; i < ret.length; i++) 
			ret[i] = Double.parseDouble(retAsStr[i]);
		return ret;
	}

	static public boolean[] parseBooleanArray(String val, String delim) {
		String[] retAsStr = parseStringArray(val, delim);
		boolean[] ret = new boolean[retAsStr.length];
		for (int i = 0; i < ret.length; i++) 
			ret[i] = Boolean.valueOf(retAsStr[i]).booleanValue();
		return ret;
	}
}
